﻿Imports System.Data.OleDb
Public Class CaChieuDAO


    Public Function Insert(ByVal tmp As CaChieuDTO) As Integer
        Dim cn As OleDbConnection = DataProvider.ConnectionData()
        Dim str As String = "insert into CACHIEU (GioBatDau, GioKetThuc) values (@GioBatDau, @GioKetThuc)"
        Dim cmd As OleDbCommand = New OleDbCommand(str, cn)

        Dim para1, para2 As OleDbParameter
        para1 = New OleDbParameter("@GioBatDau", tmp.GioBatDau)
        cmd.Parameters.Add(para1)
        para2 = New OleDbParameter("@GioKetThuc", tmp.GioKetThuc)
        cmd.Parameters.Add(para2)

        Dim result As Integer = cmd.ExecuteNonQuery()
        cn.Close()
        Return result
    End Function

    Public Function Update(ByVal tmp As CaChieuDTO) As Integer
        Dim cn As OleDbConnection = DataProvider.ConnectionData()
        Dim str As String = "update CACHIEU set GioBatDau=@GioBatDau, GioKetThuc=@GioKetThuc where MaCaChieu=@MaCaChieu"
        Dim cmd As OleDbCommand = New OleDbCommand(str, cn)

        Dim para1, para2, para3 As OleDbParameter
        para1 = New OleDbParameter("@GioBatDau", tmp.GioBatDau)
        cmd.Parameters.Add(para1)
        para2 = New OleDbParameter("@GioKetThuc", tmp.GioKetThuc)
        cmd.Parameters.Add(para2)
        para3 = New OleDbParameter("@MaCaChieu", tmp.MaCaChieu)
        cmd.Parameters.Add(para3)

        Dim result As Integer = cmd.ExecuteNonQuery()
        cn.Close()
        Return result
    End Function

    Public Function Delete(ByVal tmp As CaChieuDTO) As Integer
        Dim cn As OleDbConnection = DataProvider.ConnectionData()
        Dim str As String = "delete from CACHIEU where MaCaChieu=@MaCaChieu"
        Dim cmd As OleDbCommand = New OleDbCommand(str, cn)

        Dim para1 As OleDbParameter
        para1 = New OleDbParameter("@MaCaChieu", tmp.MaCaChieu)
        cmd.Parameters.Add(para1)

        Dim result As Integer = cmd.ExecuteNonQuery()
        cn.Close()
        Return result
    End Function
    Public Function GetTable(ByVal t As String) As DataTable
        Dim dt As DataTable = New DataTable()
        Dim cn As OleDbConnection = DataProvider.ConnectionData()
        Dim str As String = t
        Dim da As OleDbDataAdapter = New OleDbDataAdapter(str, cn)
        da.Fill(dt)
        cn.Close()
        Return dt
    End Function
End Class
